//
//  LeaveContentViewController.swift
//  BellManage
//
//  Created by Bestsch on 16/4/13.
//  Copyright © 2016年 wsl. All rights reserved.
//

import UIKit

class LeaveContentViewController: BaseViewController,UITableViewDelegate,UITableViewDataSource {

    
    var tableView: UITableView!
    
    var classid: String!
    var className: String!
    
    var array = NSMutableArray()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        self.title = "今日请假"
        
        InitViews()
    }
    
    func InitViews()  {
        
        tableView = UITableView.init(frame: CGRect(x: 0, y: 0, width: screenW, height: screenH), style: UITableViewStyle.plain)
        tableView.delegate = self
        tableView.dataSource = self
        tableView.backgroundColor = UIColor.init(hexString: "f6f6f6", alpha: 1)
        tableView.separatorStyle = UITableViewCellSeparatorStyle.none
        self.view.addSubview(tableView)
        
        setUpRefresh()
    }

    func setUpRefresh()  {
        
        tableView.header = MJRefreshNormalHeader.init(refreshingTarget: self, refreshingAction: #selector(LeaveContentViewController.refresh))
        tableView.header.beginRefreshing()
        
    }
    
    func refresh()  {
        /**
         t=23  //今日请假的学生列表
         XmlNode schseridxml = ndoc.SelectSingleNode("//rss/channel/sch");
         XmlNode classidxml = ndoc.SelectSingleNode("//rss/channel/cla");
         */
        let user = getUserPojo()
        let request = requestHeader + "23</t><sch>" + user.schid + "</sch><cla>" + classid + "</cla></channel></rss>"
        let url = server + adminwebapppi
        do{
            array =  getData(url, request: request)
        }catch{
            
        }
        
        if array.count == 0 {
            TSMessage.showNotification(in: self, title: "提示", subtitle: className + "，该班级今日没有学生请假！" , image: nil, type: TSMessageNotificationType.error, duration: 3.0, callback: nil, buttonTitle: "知道了", buttonCallback: nil, at: TSMessageNotificationPosition.top, canBeDismissedByUser: true)
        }
        tableView.reloadData()
        tableView.header.endRefreshing()
        
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 130
    }
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
        
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return array.count
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cellIdentifier = "LeaveTableViewCellIdentifier";
        let dic = array[indexPath.row] as! JSON
        let cell = LeaveTableViewCell(dic: dic, reuseIdentifier: cellIdentifier)
        cell.selectionStyle = UITableViewCellSelectionStyle.none;
        return cell
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
